<?php
defined('IN_IA') or exit('Access Denied');

global $_W, $_GPC;
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
//视频列表页
if ($op == 'display') {

    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $condition = " uniacid = '{$_W['uniacid']}'";
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('aide_activity_video') . " WHERE $condition");
    $video=pdo_fetchall("SELECT * FROM " . tablename('aide_activity_video') . " WHERE uniacid='{$_W['uniacid']}' ORDER BY  id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
    //记录总数
    $pager = pagination($total, $pindex, $psize);
    include aide_template ('video');
    exit;
}

if ($op == 'post') {
    $videoid = intval($_GPC['videoid']);
    $video=pdo_fetchall("SELECT * FROM " . tablename('aide_activity_video') . " WHERE id=$videoid ORDER BY  id ASC LIMIT 1");
    $video=$video[0];
    $time=date('Y-m-d H:i:s');
    if (checksubmit('submit')) {
        $form = $_GPC['video'];
        $data['uniacid'] = $_W['uniacid'];
        $data['file_path'] = $form['file_path'];
        $data['title'] = $form['title'];
        $data['hits'] = $form['hits'];
        $data['recom'] = $form['recom'];
        $data['updated_at'] = $time;
        if (!empty($videoid)) {
            pdo_update ('aide_activity_video', $data, array ('id' => $videoid));
        } else {
            $data['created_at'] = $time;
            pdo_insert ('aide_activity_video', $data);
            $activityid = pdo_insertid();
        }
        message ('更新成功！', web_url('video/video/display'), 'success');
    }
    include aide_template ('video');
    exit;
}
if ($op == 'pass' && $_W['isajax']) {
    $id = $_GPC['id'];
    $img = (string)$_GPC['img'];
    $arr=['img'=>$img];
    $result = pdo_update ('aide_activity_video', $arr, array ('id' => $id));
    die(json_encode(array('result'=>$result,)));
}
if ($op == 'delete') {
    $videoid = intval($_GPC['videoid']);
    pdo_delete ('aide_activity_video', array ('id' => $videoid));
    die(json_encode(array("errno" => 0,'message'=>'删除成功')));
    exit;
}
